package main.Q1101_1200;

import java.util.Stack;

public class Q1181_1190 {
    public static void main(String[] args) {
        System.out.println("Question1181：");
        System.out.println("Question1182：");
        System.out.println("Question1183：");
        System.out.println("Question1184：");
        System.out.println("Question1185：");
        System.out.println("Question1186：");
        System.out.println("Question1187：");
        System.out.println("Question1188：");
        System.out.println("Question1189：");
        System.out.println("Question1190：反转每对括号间的子串");
        System.out.println(new Question1190().reverseParentheses("(abcd)"));
    }
}

class Question1190 {
    public String reverseParentheses(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()) {
            if (c == ')') {
                StringBuffer temp = new StringBuffer();
                while (stack.peek() != '(') {//翻转
                    temp.append(stack.pop());
                }
                stack.pop();//去除括号
                for (char cur : temp.toString().toCharArray()) {
                    stack.add(cur);
                }
            } else {
                stack.add(c);
            }
        }
        StringBuffer result = new StringBuffer();
        while (!stack.isEmpty()) {
            result.append(stack.pop());
        }
        return result.reverse().toString();
    }
}